package com.xxgc.vfc.common.error.center;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.net.InetAddress;
import java.net.UnknownHostException;

/*
 *
 *   @Author:m
 *   @Date: 2023/11/8-11-08-9:01
 *   工程中所有自定义异常的父类
 */
@AllArgsConstructor
@NoArgsConstructor
@Component
@Data
public class BaseException extends RuntimeException implements Serializable {

    //哪个服务报的错
    @Value("${spring.application.name}")
    private String server;
    //报错机器的ip地址
    private String ipAddress;
    //错误码
    private String code;
    //传入参数
    private Object args;
    //错误信息
    private String errorMessage;
    //接口信息
    private String interfaceInfo;
    //错误方法信息
    private String methodInfo;

    public BaseException(String code, String errorMessage) {
        //获取本机ip地址
        InetAddress ipAddress = null;
        try {
            ipAddress = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        this.ipAddress = ipAddress.getHostAddress();
        this.code = code;
        this.errorMessage = errorMessage;
    }
}
